package com.ruoyi.project.business.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.business.domain.BusinessArea;
import com.ruoyi.project.business.domain.BusinessAreaOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.business.mapper.BusinessAreaMapper;
import com.ruoyi.project.business.service.IBusinessAreaService;

/**
 * 租地土地Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-10-19
 */
@Service
public class BusinessAreaServiceImpl implements IBusinessAreaService 
{
    @Autowired
    private BusinessAreaMapper businessAreaMapper;

    /**
     * 查询租地土地
     * 
     * @param id 租地土地ID
     * @return 租地土地
     */
    @Override
    public BusinessArea selectBusinessAreaById(Long id)
    {
        return businessAreaMapper.selectBusinessAreaById(id);
    }

    /**
     * 查询租地土地列表
     * 
     * @param businessArea 租地土地
     * @return 租地土地
     */
    @Override
    public List<BusinessArea> selectBusinessAreaList(BusinessArea businessArea)
    {
        return businessAreaMapper.selectBusinessAreaList(businessArea);
    }

    /**
     * 新增租地土地
     * 
     * @param businessArea 租地土地
     * @return 结果
     */
    @Override
    public int insertBusinessArea(BusinessArea businessArea)
    {
        businessArea.setCreateTime(DateUtils.getNowDate());
        businessAreaMapper.insertBusinessArea(businessArea);
        BusinessArea businessArea1=businessAreaMapper.selectBusinessAreaById(businessArea.getId());
        businessArea1.setLandCode("A"+String.format("%08d",businessArea.getId() ));
        businessAreaMapper.updateBusinessArea(businessArea1);
        System.out.println(businessArea1.getLandCode());
        return 1;
    }

    /**
     * 修改租地土地
     * 
     * @param businessArea 租地土地
     * @return 结果
     */
    @Override
    public int updateBusinessArea(BusinessArea businessArea)
    {
        businessArea.setUpdateTime(DateUtils.getNowDate());
        return businessAreaMapper.updateBusinessArea(businessArea);
    }

    /**
     * 批量删除租地土地
     * 
     * @param ids 需要删除的租地土地ID
     * @return 结果
     */
    @Override
    public int deleteBusinessAreaByIds(Long[] ids)
    {
        return businessAreaMapper.deleteBusinessAreaByIds(ids);
    }

    /**
     * 删除租地土地信息
     * 
     * @param id 租地土地ID
     * @return 结果
     */
    @Override
    public int deleteBusinessAreaById(Long id)
    {
        return businessAreaMapper.deleteBusinessAreaById(id);
    }

    /**
     * 定时任务修改土地状态
     * @param businessArea 租地土地
     * @return
     */
    @Override
    public int updateBusinessAreaStatus() {
        //查询土地订单土地是否到期

        List<BusinessAreaOrder> list = businessAreaMapper.selectBusinessAreaOrder();

        for(int i=0;i<list.size();i++){
            businessAreaMapper.updateBusinessAreaStatus(list.get(i).getAreaId());
        }
        return 1;
    }
}
